import time

from selenium.webdriver.common.by import By

from common.Utils import ForumDriver
#测试论坛登录页面

class ForumLogin:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:58080/sign-in.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)
    #成功登录的测试用例
    def LoginSucTest(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("夏诗涵")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        #查看是否登录成功
        self.driver.implicitly_wait(3)
        self.driver.find_element(By.CSS_SELECTOR,"#nav_board_index > a > span.nav-link-title")
        #添加屏幕截图
        # ForumDriver.getScreeShot()
        # self.driver.back()
    #异常登录的测试用例
    #  账户正确-密码为空
    def LogFailTest1(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("张三")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        #获取错误文本
        actual=self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-2 > div > div").text
        print(actual)
        ForumDriver.getScreeShot()
        assert actual == "密码不能为空"

    #  账户为空-密码正确
    def LogFailTest2(self):
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        #获取错误文本
        actual=self.driver.find_element(By.CSS_SELECTOR,"#signInForm > div.mb-3 > div").text
        print(actual)
        ForumDriver.getScreeShot()
        self.driver.implicitly_wait(3)
        assert actual == "用户名不能为空"


login=ForumLogin()
login.LoginSucTest()
# # login.LogFailTest1()
# login.LogFailTest2()